package com.shanxia.codec.cmd;

import com.shanxia.codec.ProtocolDataBase;
import lombok.Data;

import static com.shanxia.codec.Decoder.byteToAscii;
import static com.shanxia.codec.Decoder.encodeAscii;

/**
 * S -> C
 * 服务器下发升级文件数据
 */
@Data
public class Cmd1007 extends ProtocolDataBase {

    private String data;            // 升级文件数据

    public Cmd1007(){
        super.setCmd(1007);
    }

    public static Cmd1007 decodeFromBase(ProtocolDataBase protocolDataBase) {
        Cmd1007 cmd = new Cmd1007();
        cmd.copyDataFrom(protocolDataBase);
        byte[] dataField = protocolDataBase.getDataField();
        cmd.data = byteToAscii(dataField, false);
        return cmd;
    }

    @Override
    public byte[] getDataField() {
        byte[] data = new byte[this.data.length()];
        encodeAscii(data, this.data, this.data.length(), 0);
        return data;
    }
}
